//
//    Main script of Ajax v1.0 Bootstrap Theme
//
"use strict";
/*-------------------------------------------
	Dynamically load plugin scripts
---------------------------------------------*/

function LoadDemoScript(callback){
	if (!$.fn.social){
        //console.log(callback);
		$.getScript('js/ajax-demo.js', callback);
	}
	else {
		if (callback && typeof(callback) === "function") {
			callback();
		}
	}
}


function LoadDefaultScript(callback){
	if (callback && typeof(callback) === "function") {
        callback();
    }
}

function LoadSocialScript(callback){
	if (callback && typeof(callback) === "function") {
        callback();
    }
}

function LoadButtonsScript(callback){
	if (callback && typeof(callback) === "function") {
        callback();
    }
}

function LoadWidgetsScript(callback){
	if (callback && typeof(callback) === "function") {
        callback();
    }
}

function LoadFormComponentsScript(callback){
	if (!$.fn.formComponents){//bootstrapSwitch,不知道为什么还需要再加载
		$.getScript('js/bootstrap-switch.min.js', callback);
    }
	else {
		if (callback && typeof(callback) === "function") {
			callback();
		}
	}
}

function LoadFormAdvancedScript(callback){
    if (callback && typeof(callback) === "function") {
        callback();
    }
//	if (!$.fn.formAdvanced){
//		$.getScript('js/bootstrap-switch.min.js', callback);
//    }
//	else {
//		if (callback && typeof(callback) === "function") {
//			callback();
//		}
//	}
}


function LoadChartsScript(callback){
	if (callback && typeof(callback) === "function") {
        callback();
    }
}

function LoadGalleryScript(callback){
	if (callback && typeof(callback) === "function") {
        callback();
    }
}

function LoadDatatablesScript(callback){
	if (callback && typeof(callback) === "function") {
        callback();
    }
}


function LoadDatatablesEditableScript(callback){
//    function LoadDatatablesEditable(){
//		$.getScript('js/jquery.datatables.min.js', function(){
//			$.getScript('js/datatable-editable.js', callback);
//		});
//	}
//	if (!$.fn.dataTablesEditable){
//		LoadDatatablesEditable();
//	}
//	else {
//		if (callback && typeof(callback) === "function") {
//			callback();
//		}
//	}
}


function LoadCalendarScript(callback){
	if (callback && typeof(callback) === "function") {
        callback();
    }
}



/*-------------------------------------------
	Main scripts used by theme
---------------------------------------------*/
//
//  Function for load content from url and put in $('.ajax-content') block
//
function LoadAjaxContent(url){
	//$('.preloader').show();
	$.ajax({
		mimeType: 'text/html; charset=utf-8', // ! Need set mimeType only when run from local file
		url: url,
		type: 'GET',
		success: function(data) {
			$('#ajax-content').html(data);
			//$('.preloader').hide();
		},
		error: function (jqXHR, textStatus, errorThrown) {
			alert(errorThrown);
		},
		dataType: "html",
		async: false
	});
}


//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
//
//      MAIN DOCUMENT READY SCRIPT OF DEVOOPS THEME
//
//      In this script main logic of theme
//
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
$(document).ready(function () {
	var ajax_url = location.hash.replace(/^#/, '');
	if (ajax_url.length < 1) {
		ajax_url = 'ajax/default.html';
	}
	LoadAjaxContent(ajax_url);
    $('body').on('click', 'a', function (e) {
		if ($(this).hasClass('ajax-link')) {
			e.preventDefault();
			if ($(this).hasClass('add-full')) {
				//$('#content').addClass('full-content');
			}
			else {
				//$('#content').removeClass('full-content');
			}
			var url = $(this).attr('href');
			window.location.hash = url;
			LoadAjaxContent(url);
		}
		if ($(this).attr('href') == '#') {
			e.preventDefault();
		}
	});
});